Experimental design: Switching every 4 trials in an alternating runs manner (no cues). Total of 8 experimental blocks were intended, but 60 subjects saw only 7 blocks. Across these blocks counterbalancing of four conditions: Both tasks unambiguous (1), both tasks ambiguous (4), shape ambiguous when irrelevant, color always ambiguous (2), shape always ambiguous, color unambiguous when irrelevant (2)
What the variables mean:
block: 0 for practice, there are a total of 8 blocks per part and each block consists of 112 trials. So 896 trials per participant over all 7 blocks (not counting practice)
bal: counterbalancing of conditions across blocks
x, y, c2: irrelevant (already taken out)
cycle: counting within full alternating cycle (8), switch at 1 and 5
task: 1=shape, 2=color
dimshape=specific shapes–4=neutral
dimcolor=specific color–4=neutral
correct: correct response (i.e., value of the currently relevant task dimension)
error: 0 = no error, 1 = yes error
response: actual response
RT: or response time
Import data-set and some packages
#open neccesary packages herelibrary(tidyverse)
Warning: package 'forcats' was built under R version 4.4.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(janitor)
Attaching package: 'janitor'
The following objects are masked from 'package:stats':
chisq.test, fisher.test
library(readr)library(rio)library(psych) #generate metrix w scatterplot and cor
Attaching package: 'psych'
The following objects are masked from 'package:ggplot2':
%+%, alpha
Rows: 94754 Columns: 16
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (16): id, bal, block, x, cond, trial, y, c2, cycle, task, dim1, dim2, co...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#use pivot long and/or? wide here with some key variables we want to look at. may need to alter df to turn some 1s and 0s in columns to be names... (correct, incorrect or color, shape). fix code below...# alt_run %>% # pivot_wider(names_from = task, values_from = block)
Determine and Remove Outliers (Error way…)
# we are testing for accuracy, so we need at least 80% accuracy in all trials per participant #determine 80% accuracy crit <-896- (896* .8)crit # need at least 179 out of 896 trials to be correct, denoted by 0 in error col
#WHAT TO DO: z-score on each seq position x switch x ambiguity on RT then z-score on each block (to account for some participants only doing 7 instead of 8 blocks) #STEP 1: separate switch trials, c(1,5) and control trials !c(1,5)alt_run <- alt_run %>%mutate(trial_type =if_else(cycle %in%c(1,5), 'switch', 'control')) #saying if its 1 or 5 assign switch, else, assign control. so cool. need to also throw out the first trial after each block bc its not a switch or noswitch. need to separate into cycle positions of 4, so total conditions are 16 alt_run
#STEP 2.1: Interpret the data#so this is telling us that our mean z-score for both control and switch is basically 0 (which is what we want to see) and that our z sd is 1 (which is also what we want to see). looking at the mean for RT in both switch and control, we see that the response time means tend to be a lot longer on average than the average response time for control trials (non-switch trials). this is so cool!rtdif <- z_scoretrial %>%summarize(meandif =889.9560-579.1123) rtdif #difference in means by 310.8437 where the switch trial takes 310.84 ms longer than the control or non-switch trials.
#segregate based on cycle position and add 95% CIcycle_plot <- summary_data %>%ggplot(aes(trial_type, mean_RT)) +geom_col(fill='#9CAF88') +geom_errorbar(aes(ymin = lower_CI, ymax = upper_CI), width =0.2, color ='brown') +labs(title ='Trial Type By Response Time', subtitle ='Relationship between response times and switch/no-switch trials', x="Trial Type", y='Response Time (ms)')+theme_minimal() cycle_plot
Descriptive Graphs
1. Histogram of RT
mean_rt <-mean(alt_run$RT, na.rm =TRUE)mean_rt
[1] 860.4441
sd_rt <-sd(alt_run$RT, na.rm =TRUE)alt_run %>%ggplot(aes(x=RT)) +geom_histogram(aes(y =after_stat(density)), fill ='darkgreen', color ='darkblue') +geom_vline(aes(xintercept = mean_rt) , color ='red', linetype ='dashed', size =1.5) +theme_minimal() +stat_function(fun = dnorm, args =list(mean = mean_rt, sd = sd_rt) , col ='gold', size =1.5) +labs(x='Response Times (ms)', y='Density', title ='Density plot of Response Times', subtitle ='The mean and normal density curve of RTs')
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
plotly::ggplotly()
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.